﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BudgetKeeper
{
    class Budget
    {
        private double income, remainingTotal, remainingAfterBudget;
        public List<BudgetPost> BudgetPostList;

        public double GetIncome()
        {
            return income;
        }
        public double GetRemainingTotal()
        {
            return remainingTotal;
        }
        public double GetRemainingAfterBudget()
        {
            return remainingAfterBudget;
        }

        /// <summary>
        /// Initiates a budget
        /// </summary>
        /// <param name="income">Income</param>
        public Budget(double income)
        {
            this.income = income;
            this.remainingTotal = income;
            this.remainingAfterBudget = income;
            BudgetPostList = new List<BudgetPost>();
        }

        /// <summary>
        /// Creates a new budget post and adds it to the budget
        /// </summary>
        /// <param name="name">Name of post</param>
        /// <param name="sum">Sum of post</param>
        public void AddBudgetPost(string name, double sum)
        {
            int id = BudgetPostList.Count;
            BudgetPostList.Add(new BudgetPost(id, name, sum));
            remainingAfterBudget -= sum;
        }

        /// <summary>
        /// Add an expense in specified budget post
        /// </summary>
        /// <param name="id">Id of budget post</param>
        /// <param name="name">Name of expense</param>
        /// <param name="sum">Sum of expense</param>
        /// <param name="date">Date of expense</param>
        public void AddExpense(int id, string name, double sum, string date)
        {
            //get post
            BudgetPost bp = BudgetPostList.FirstOrDefault(o => (o.Id == id));

            if (bp != null)
            {
                bp.AddExpense(name, sum, date);
            }
            remainingTotal -= sum;
        }

        /// <summary>
        /// Update every sum (not defined yet)
        /// </summary>
        public void UpdateTotals()
        {

        }
    }
}
